package com.lwx.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyMain {
    public static void main(String[] args) {
        final Work work = new StudentWork();
        Work proxyObj = (Work)Proxy.newProxyInstance(work.getClass().getClassLoader(), 
                work.getClass().getInterfaces(), new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("before invoke");
                        //method.invoke(work, args);
                        Object obj = method.invoke(work, args);
                        System.out.println("after invoke");
                        return obj;
                    }
                });
//        System.out.println(proxyObj);
//        System.out.println("");
        proxyObj.doWork();
    }
}
